package com.mcx.visplat.mapper;

import com.mcx.visplat.pojo.Station;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

public interface StationMapper {
    @Select("SELECT cs.`city_name`,cs.`station_id`,sh.`time`,sh.`AQI`,sh.`CO`,sh.`NO2`,sh.`O3`,sh.`PM10`,sh.`PM25`,sh.`SO2` \n" +
            "FROM city_station AS cs LEFT JOIN station_history AS sh \n" +
            "ON cs.`station_id` = sh.`station_id`  \n" +
            "WHERE cs.`id` = #{station_id} and sh.time <= #{time} ORDER BY TIME DESC LIMIT 0,24")
    List<Station> getLastStationInfo(@Param("station_id") int station_id,@Param("time") String time);

    @Select("SELECT cs.`city_name`,cs.`station_id`,sh.`time`,sh.`AQI`,sh.`CO`,sh.`NO2`,sh.`O3`,sh.`PM10`,sh.`PM25`,sh.`SO2` \n" +
            "FROM city_station AS cs LEFT JOIN station_history AS sh \n" +
            "ON cs.`station_id` = sh.`station_id`  \n" +
            "WHERE cs.`id` = #{stationId} and sh.time between  #{startTime} and #{endTime} ORDER BY TIME")
    List<Station> getTimeslotStationInfo(@Param("stationId") int stationId,@Param("startTime") String startTime,@Param("endTime") String endTime);


    @Select({"<script>" +
                "SELECT cs.`city_name`,cs.`station_id`,sh.`time`,sh.`AQI`,sh.`CO`,sh.`NO2`,sh.`O3`,sh.`PM10`,sh.`PM25`,sh.`SO2`\n" +
                "FROM city_station AS cs LEFT JOIN station_history AS sh \n" +
                "ON cs.`station_id` = sh.`station_id` \n" +
                "where sh.time = #{time}  and cs.`id` in \n"+
                  "<foreach collection='station_id' item='id' open='(' separator=',' close=')'>#{id}</foreach> \n"+
            "</script>"})
    List<Station> getStationsInfo(@Param("station_id") Integer[] station_id,@Param("time") String time);
}
